<template>
    <div class="header">
        <div class="l-content">
            <el-button size="small" @click="handleCollapse">
                <component class="icons" is="menu"></component>
            </el-button>
            <el-breadcrumb :separator-icon="ArrowRight" class="bread">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item v-if="current" :to="current.path">{{ current.label }}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="r-content">
            <el-dropdown>
                <span class="el-dropdown-link">
                    <img :src="getImageUrl('user')" class="user">
                </span>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item>个人中心</el-dropdown-item>
                        <el-dropdown-item @click="handleLoginOut">退出</el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
    </div>
</template>

<script setup lang="js">
import { useAllDataStore } from '@/store'
import { computed } from 'vue';
import { useRouter } from 'vue-router';
const getImageUrl = (user) => {
    return new URL(`../assets/images/${user}.png`, import.meta.url).href
}
const store = useAllDataStore()
const handleCollapse = () => {
    store.state.isCollapse = !store.state.isCollapse //取反
}
const router = useRouter();
const handleLoginOut = () => {
    store.clean()//清除store里面的数据
    router.push('/login')//跳到登录页
}
const current = computed(() => store.state.currentMenu)
</script>

<style scoped lang="less">
.header {
    display: flex; //弹性布局
    justify-content: space-between; //主轴方向贴两边
    align-items: center; //侧轴方向垂直居中
    width: 100%;
    height: 100%;
    background-color: #333;

    .l-content {
        display: flex;
        align-items: center;

        .el-button {
            margin-right: 20px;

            .icons {
                width: 20px;
                height: 20px;
            }
        }
    }

    .r-content {
        .user {
            width: 40px;
            height: 40px;
            border-radius: 50%;
        }
    }
}

// 样式穿透
:deep(.bread span) {
    color: #fff !important;
    cursor: pointer !important; //当鼠标放上去的时候鼠标变成小手
}
</style>
